package com.kun.index.controller;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kun.common.Constants;
import com.kun.common.ResultDto;
import com.kun.common.annotation.PermissionAuthentication;
import com.kun.index.entity.Blog;
import com.kun.index.service.impl.AttachServiceImpl;
import com.kun.index.service.impl.BlogServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 附件表 前端控制器
 * </p>
 *
 * @author kunkun
 * @since 2024-02-29
 */
@RestController
@RequestMapping("/index/attach")
public class AttachController {

    @Autowired
    private AttachServiceImpl attachService;

    @Value("${file.upload.pictureFilePrefix}")
    private String pictureFilePrefix;

    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public ResultDto uploadAttach(@RequestParam("file") MultipartFile file){

        String url = attachService.uploadAttach(file);

        return ResultDto.success(pictureFilePrefix +url);

    }

    @GetMapping("/uploadTyporaPlugin")
    @ApiOperation("上传文件-Typora插件")
    @PermissionAuthentication
    public String uploadTyporaPlugin(@RequestParam("fileLocalAddress") String fileLocalAddress){
            String url = attachService.uploadAttachByString(fileLocalAddress);

            return pictureFilePrefix +url;

    }

}

